package ${packageName}.controller;

import ${packageName}.entity.${entityName};
import ${packageName}.service.I${entityName}Service;

import com.admin.boot.common.utils.QueryGenerator;
import com.admin.boot.common.utils.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @version v3.0
* @Description: TODO
* @author: admin-boot
* @date: ${.now?string("yyyy-MM-dd")}
*/
@Api(tags = "${tableDescribe}")
@RestController
@RequestMapping("/${entityName?uncap_first}/${entityName?uncap_first}")
public class ${entityName}Controller {

    @Autowired
    private I${entityName}Service ${entityName?uncap_first}Service;

    @GetMapping("/list")
    @ApiOperation(value = "${tableDescribe}-分页列表查询", notes = "${tableDescribe}-分页列表查询")
    public Result<?> list(${entityName} ${entityName?uncap_first},
                          @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first});
        Page<${entityName}> page = new Page<>(pageNo, pageSize);
        Page<${entityName}> ${entityName?uncap_first}Page = ${entityName?uncap_first}Service.page(page, queryWrapper);
        return Result.OK(${entityName?uncap_first}Page);
    }

    @GetMapping("/queryList")
    @ApiOperation(value = "${tableDescribe}-分页列表查询", notes = "${tableDescribe}-分页列表查询")
    public Result<?> queryList(${entityName} ${entityName?uncap_first}) {
        List<${entityName}> list = ${entityName?uncap_first}Service.list(null);
        return Result.OK(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "${tableDescribe}-添加", notes = "${tableDescribe}-添加")
    public Result<?> add(@RequestBody ${entityName} ${entityName?uncap_first}) {
        ${entityName?uncap_first}Service.save(${entityName?uncap_first});
        return Result.OK("添加成功！");
    }


    @PostMapping("/edit")
    @ApiOperation(value = "${tableDescribe}-编辑", notes = "${tableDescribe}-编辑")
    public Result<?> edit(@RequestBody ${entityName} ${entityName?uncap_first}) {
        ${entityName?uncap_first}Service.updateById(${entityName?uncap_first});
        return Result.OK("编辑成功！");
    }

    @GetMapping("/deleteById")
    @ApiOperation(value = "${tableDescribe}-删除", notes = "${tableDescribe}-删除")
    public Result<?> deleteById(String id) {
        ${entityName?uncap_first}Service.removeById(id);
        return Result.OK("删除成功！");
    }

    @GetMapping("/deleteBatch")
    @ApiOperation(value = "${tableDescribe}-批量删除", notes = "${tableDescribe}-批量删除")
    public Result<?> deleteBatch(String ids) {
        for (String id : ids.split(",")) {
            ${entityName?uncap_first}Service.removeById(id);
        }
        return Result.OK("删除成功！");
    }

}
